﻿using ai_library;
using System.Collections;
using UnityEngine;

public class AiObstacleBehavior : MonoBehaviour 
{
	public IEntity Entity
	{
		get;
		private set;
	}

	void Awake()
	{
		Entity = null;
	}
	
	void Start () 
	{
		Transform trans = gameObject.transform;
		
		try
		{
			Entity = EntityFactory.Get(EntityTypes.Agent, trans);
		}
		catch (EntityFactoryException e)
		{
			Debug.Log (e.ToString());
		}
		
		if (EntityManager.Instance.IsAgentRegistered(Entity))
		{
			Debug.Log("Entity " + Entity.ID + "already registered to EntityManager?");
		}
		else
		{
			EntityManager.Instance.RegisterAgent(Entity);
		}
	}

	void Update () 
	{
		try
		{
			Entity.Update(Time.deltaTime);
		}
		catch(EntityException e)
		{
			Debug.Log(e.ToString());
		}
	}
}
